package com.zenithmind.article.controller;

import com.zenithmind.common.annotation.Log;
import com.zenithmind.common.constant.OperationTypeEnum;
import com.zenithmind.article.pojo.domain.Comment;
import com.zenithmind.article.pojo.query.CommentQuery;
import com.zenithmind.article.pojo.vo.CommentPageVO;
import com.zenithmind.article.service.CommentService;
import com.zenithmind.common.result.PageResult;
import com.zenithmind.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/zenithMind/comment")
@Tag(name = "评论管理")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @Log(description = "添加或修改评论", operationType = OperationTypeEnum.UPDATE)
    @Operation(summary = "添加或修改评论")
    @PostMapping("/saveOrUpdateComment")
    public Result<Comment> saveOrUpdateComment(@RequestBody Comment comment) {
        Comment savedComment = commentService.saveOrUpdateComment(comment);
        return Result.success(savedComment);
    }

    @Log(description = "添加评论", operationType = OperationTypeEnum.ADD)
    @Operation(summary = "添加评论")
    @PostMapping("/addComment")
    public Result<Comment> addComment(@RequestBody Comment comment) {
        Comment addedComment = commentService.addComment(comment);
        return Result.success(addedComment);
    }

    @Log(description = "删除评论", operationType = OperationTypeEnum.DELETE)
    @Operation(summary = "删除评论")
    @DeleteMapping("/deleteComment")
    public Result<Void> deleteComment(@RequestBody String id) {
        commentService.removeById(id);
        return Result.success();
    }

    @Log(description = "分页查询评论", operationType = OperationTypeEnum.QUERY)
    @Operation(summary = "分页查询评论")
    @GetMapping("/pageComment")
    public Result<PageResult<CommentPageVO>> pageComment(CommentQuery commentQuery) {
        PageResult<CommentPageVO> commentPageVO = commentService.pageComment(commentQuery);
        return Result.success(commentPageVO);
    }

    @Log(description = "审核评论", operationType = OperationTypeEnum.UPDATE)
    @Operation(summary = "审核评论")
    @PutMapping("/reviewComment")
    public Result<Void> reviewComment(@RequestParam String id, @RequestParam Integer status) {
        commentService.reviewComment(id, status);
        return Result.success();
    }

    @Log(description = "获取评论统计信息", operationType = OperationTypeEnum.QUERY)
    @Operation(summary = "获取评论统计信息")
    @GetMapping("/getCommentStatistics")
    public Result<Object> getCommentStatistics() {
        Object statistics = commentService.getCommentStatistics();
        return Result.success(statistics);
    }
}
